﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using Follow.Utils;
using Follow.Model;
using System.Transactions;

namespace Follow.DataAccess
{
    public class ViewFollowUpPropostaDAO
    {
        private SqlDataReader reader = null;
        private SqlConnection conn = null;
        private SqlCommand cmd = null;

        public ViewFollowUpPropostaDAO()
        {
            conn = ConnectionUtils.getConnection();
        }

        public IList<ViewFollowUpProposta> findAll(string idProposta)
        {
            IList<ViewFollowUpProposta> viewFollowProposta = new List<ViewFollowUpProposta>();
            try
            {
                conn.Open();
                String sqlCommand = " select * from vwStatusPorFollowUp where [proposta_idproposta] = " + idProposta;
                cmd = new SqlCommand(sqlCommand, conn);
                reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    ViewFollowUpProposta vfp = new ViewFollowUpProposta();
                    vfp.DescricaoStatusFollow = reader.GetString(0);
                    vfp.ObservacaoFollow = reader.GetString(1);
                    vfp.DataFollowUp = reader.GetDateTime(2);
                    vfp.IdProposta = reader.GetInt32(3);
                    vfp.IdFollowUp = reader.GetInt32(4);
                    viewFollowProposta.Add(vfp);
                }
            }
            finally
            {
                if (reader != null)
                {
                    reader.Dispose();
                    reader.Close();
                }

                if (conn != null)
                {
                    conn.Dispose();
                    conn.Close();
                }
            }
            return viewFollowProposta;

        }

    }

    
}